<?php
/**
 * 主页文件
 * @link https://codex.wordpress.org/Template_Hierarchy
 *
 * @package 古槐乡情
 * @subpackage 2017-01
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>
<div class="row">
    <div class="col-md-7">
        <div id="carousel-example-generic" class="carousel slide trends-carousel" data-ride="carousel">

            <!-- Indicators -->
            <ol class="carousel-indicators">
                <li data-target="#carousel-example-generic" data-slide-to="0" class="active"></li>
                <li data-target="#carousel-example-generic" data-slide-to="1"></li>
                <li data-target="#carousel-example-generic" data-slide-to="2"></li>
            </ol>
            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <?php 
                    $cat=get_category_by_slug("trends"); 
                    $cat_links=get_category_link($cat->term_id);
                ?>

                <?php $posts = get_posts( "category=$cat->term_id&numberposts=3" ); ?>  
                <?php if( $posts ) : ?>  
                    <?php foreach( $posts as $key=>$post ) : setup_postdata( $post ); ?>
                        <?php  if ($key==0) :?>
                            <div class="item active">
                        <?php else : ?>

                        <div class="item">
                        <?php endif; ?>
                        <a href="<?php the_permalink() ?>" rel="bookmark" title="<?php the_title(); ?>" alt="<?php the_title(); ?>">
                            <?php the_post_thumbnail(array(652,293));?>
                        </a>
                    </div>
                    <?php endforeach; ?>  
                <?php endif; ?>

            </div>
            <!-- Controls -->
            <a class="left carousel-control" href="#carousel-example-generic" role="button" data-slide="prev">
                <span class="glyphicon glyphicon-chevron-left"></span>
                <span class="sr-only">上一个</span>
            </a>
            <a class="right carousel-control" href="#carousel-example-generic" role="button" data-slide="next">
                <span class="glyphicon glyphicon-chevron-right"></span>
                <span class="sr-only">下一个</span>
            </a>
        </div>

        <!--名家推荐-->
        <div class="panel hlgd-title">
            <?php 
                $cat=get_category_by_slug("member"); 
                $cat_links=get_category_link($cat->term_id);
            ?>
            <div class="panel-heading">名家推荐<span><a href="<?php echo $cat_links; ?>">更多..</a></span></div>
            <hr>
            <div class="panel-body imgteaser">
                <?php 
                $sticky = get_option('sticky_posts'); //获得所有置顶文章的id
                $args = array(
                    'numberposts' => 8, // 最多获取6篇置顶文章
                    'post__in'  => $sticky,
                    'category'  => $cat->term_id,
                    'meta_key' => 'sort',
                    'orderby' => 'meta_value'
                );
                $posts = get_posts($args);?>  
                <?php if( $posts ) : ?>  
                <?php foreach( $posts as $post ) : setup_postdata( $post );?> 

                <div class="col-xs-3 col-md-3 photoa">
                    <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
                        <?php the_post_thumbnail(array(143,143) );?>
                        <div class="bwidt">
                            <span class="stxt">
                                <?php the_title(); ?>
                            </span>
                        </div>
                    </a>
                </div>

                <?php endforeach; ?>  
                <?php endif; ?>

            </div>
        </div>
    </div>
    <div class="col-md-5">
        <!--最新动态-->
        <div class="panel hlgd-title">
        	<?php 
	            $cat=get_category_by_slug("trends"); 
	            $cat_links=get_category_link($cat->term_id);
            ?>
            <div class="panel-heading"><?php echo $cat->name; ?><span><a href="<?php echo $cat_links; ?>">更多..</a></span></div>
            <hr>
            <div class="panel-body">
            	<?php $posts = get_posts( "category=$cat->term_id&numberposts=8" ); ?>  
				<?php if( $posts ) : ?>  
				<ul class="newsul">
					<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>  
					<li>  
						<span><?php the_time('y-m-d'); ?></span>
                        <div>
                          <a href="<?php the_permalink() ?>" rel="”bookmark”" title="<?php the_title(); ?>">
                            <?php echo wp_trim_words(get_the_title(),14); ?>
                          </a>
                        </div> 
					</li>  
				<?php endforeach; ?>  
				</ul>  
				<?php endif; ?>
            </div>
        </div>

        <!--最新资讯-->
        <div class="panel hlgd-title">
            <?php 
	            $cat=get_category_by_slug("news"); 
	            $cat_links=get_category_link($cat->term_id);
            ?>
            <div class="panel-heading"><?php echo $cat->name; ?><span><a href="<?php echo $cat_links; ?>">更多..</a></span></div>
            <hr>
            <div class="panel-body">
            	<?php $posts = get_posts( "category=$cat->term_id&numberposts=9" ); ?>  
				<?php if( $posts ) : ?>  
				<ul class="newsul">
					<?php foreach( $posts as $post ) : setup_postdata( $post ); ?>  
					<li>
                        <span><?php the_time('m-d'); ?></span>
                        <div>
						  <a href="<?php the_permalink() ?>" rel="”bookmark”" title="<?php the_title(); ?>">
                            <?php echo wp_trim_words(get_the_title(),14); ?>
						  </a>
                        </div> 
					</li>  
				<?php endforeach; ?>  
				</ul>  
				<?php endif; ?>
            </div>
        </div>
    </div>
</div>
<!--作品展示-->
<div class="panel hlgd-title">
    <?php 
        $cat=get_category_by_slug("show"); 
        $cat_links=get_category_link($cat->term_id);
    ?>
    <div class="panel-heading"><?php echo $cat->name; ?><span><a href="<?php echo $cat_links; ?>">更多..</a></span></div>
    <hr>
    <div class="panel-body imgteaser">
            <?php $posts = get_posts( "category=$cat->term_id&numberposts=8&orderby=sort" ); ?>  
            <?php if( $posts ) : ?>  
            <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>  
            <div class="col-md-3 photob">
                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
                    <?php the_post_thumbnail(array(250,120));?>
                    <div class="bwidt">
                        <span class="stxt">
                            <?php the_title(); ?>
                        </span>
                    </div>
                </a>
            </div>
            <?php endforeach; ?>  
            <?php endif; ?>
    </div>
</div>
<!-- 广告位 -->
<div>
    <a href="#">
        <!-- <img class="img-responsive center-block" src="http://upload.8mhh.com/2015/0409/1428583787433.gif" alt="水墨基金" width="885"> -->
    </a>
</div>
<!-- /广告位 -->


<!--协会会员-->
<div class="panel hlgd-title">
    <?php 
        $cat=get_category_by_slug("member"); 
        $cat_links=get_category_link($cat->term_id);
    ?>
    <div class="panel-heading"><?php echo $cat->name; ?><span><a href="<?php echo $cat_links; ?>">更多..</a></span></div>
    <hr>
    <div class="panel-body imgteaser">
        <?php 

        $sticky = get_option('sticky_posts'); //获得所有置顶文章的id
        $args = array(
            'numberposts' => 12,
            'post__not_in'  => $sticky,
            'category'  => $cat->term_id,
            'meta_key' => 'sort',
            'orderby' => 'meta_value'
        );
        $posts = get_posts($args);?>  
        <?php if( $posts ) : ?>  
        <?php foreach( $posts as $post ) : setup_postdata( $post );?>  
            <div class="col-xs-3 col-md-2 photoa">
                <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
                    <?php the_post_thumbnail(array(145,145));?>
                    <div class="bwidt">
                        <span class="stxt">
                            <?php the_title(); ?>
                        </span>
                    </div>
                </a>
            </div>
        <?php endforeach; ?>  
        <?php endif; ?>
    </div>
</div>

<div class="row">
    <!--协会简介-->
    <div class="col-md-6">
        <div class="panel hlgd-title">
            <?php 
                $cat=get_category_by_slug("about"); 
                $cat_links=get_category_link($cat->term_id);
            ?>
            <div class="panel-heading"><?php echo $cat->name; ?></div>
            <hr>
            <div class="panel-body">
                <?php $posts = get_posts( "category=$cat->term_id&numberposts=1" ); ?>  
                <?php if( $posts ) : ?>  

                <div class="media">
                    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>  
                    <a class="media-left" href="<?php the_permalink() ?>">
                        <?php the_post_thumbnail(array(200,200) );?>
                    </a>
                    <div class="media-body">
                        <h4 class="media-heading"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
                        <p>
                            <?php echo wp_trim_words(get_the_content(),100); ?>
                        </p>
                    </div>
                    <?php endforeach; ?>  
                </div>
                <?php endif; ?>
            </div>
        </div>
    </div>
    <!--协会刊物-->
    <div class="col-md-6">
        <div class="panel hlgd-title">
            <?php 
                $cat=get_category_by_slug("periodical"); 
                $cat_links=get_category_link($cat->term_id);
            ?>
            <div class="panel-heading"><?php echo $cat->name; ?><span><a href="<?php echo $cat_links; ?>">更多..</a></span></div>
            <hr>
            <div class="panel-body">
                <?php $posts = get_posts( "category=$cat->term_id&numberposts=1" ); ?>  
                <?php if( $posts ) : ?>  
                <div class="media">
                    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>  
                    <a class="media-left" href="<?php the_permalink() ?>">
                        <?php the_post_thumbnail(array(200,200));?>
                    </a>
                    <div class="media-body">
                        <h4 class="media-heading"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h4>
                        <p>
                            <?php echo wp_trim_words(get_the_content(),100); ?>
                        </p>
                    </div>
                <?php endforeach; ?>  
                </div>
                <?php endif; ?>

            </div>
        </div>
    </div>
</div>

<?php get_footer(); ?>